import React from 'react';
import {Button, Icon, message, Checkbox, Radio,Modal} from 'antd';
const RadioGroup = Radio.Group;
import {WeaDialog, WeaSearchGroup, WeaFormItem, WeaBrowser, WeaInput, WeaSelect, WeaTextarea, WeaTable,WeaTools, WeaError, WeaHelpfulTip} from 'ecCom';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

// 外部数据元素，数据来源
class Content_OutData_DataSource extends React.Component {
    state = {
        id: this.props.tabData.id,
        title: this.props.tabData.title || '',
        sourceType: this.props.tabData.sourceType || this.props.tabNew.sourceType,
        dataSourceList: this.props.tabData.dataSourceList || [],
        dataSourceType: this.props.tabData.dataSourceType || this.props.tabNew.dataSourceType.selected,
        dataSource: this.props.tabData.dataSource || this.props.tabNew.dataSource.selected,
        content: this.props.tabData.content,
        primaryKey: this.props.tabData.primaryKey,
        linkAddress: this.props.tabData.linkAddress,
        integrateLogin: this.props.tabData.integrateLogin || this.props.tabNew.integrateLogin.selected,
        showFieldSetting: this.props.tabData.showFieldSetting || [],
        dsModalVisible: true,
        wsaddress: '',
        method: '',
        parameters: '',
        ismatch:true,
        selectedRowKeys:[]
    };

    constructor(props) {
        super(props);
        this.getButtons = this.getButtons.bind(this);
        this.onOk = this.onOk.bind(this);
        this.onCancel = this.onCancel.bind(this);
        this.onAdd = this.onAdd.bind(this);
        this.onDelete = this.onDelete.bind(this);
        this.onShowFieldChange = this.onShowFieldChange.bind(this);
    }
    render() {
        const {
            title, sourceType, dataSourceList, dataSourceType, dataSource, content,
            primaryKey, linkAddress, integrateLogin, showFieldSetting,wsaddress,method,parameters
        } = this.state;
        const {tabNew} = this.props;
        let existSetting = <div></div>;
        let customSetting = <div></div>;
        let fieldSetting = <div></div>;
        let dataSourceSetting = <div></div>
        if(dataSourceType=='1'){
            dataSourceSetting = (<div><WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@5tnmye`} label={getLabel(18076,"数据源")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@nl9paw`}
                            options={
                                tabNew.dataSource.options.map((item) => {
                                    return {key: item.key, selected: false, showname: item.value};
                                })
                            }
                            value={dataSource}
                            style={{width: '120px'}}
                            onChange={(value) => this.setState({dataSource: value})}
                        />
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@95gn16`} label={getLabel(33368,"内容")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@txwmgg`}
                            ref={el => {this.content = el}}
                            tipPosition='bottom'
                            error={getLabel(388425,"内容未填写")}
                            style={{width: '100%'}}
                        >
                            <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@cm1d52`}
                                className='portal-eoutdata-submit'
                                value={content}
                                viewAttr={3}
                                minRows={4}
                                onChange={value => {
                                    this.setState({content: value})
                                }}
                            />
                        </WeaError>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@chhita`} label={getLabel(21027,"主键")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@99663n`}
                            ref={el => {this.primaryKey = el}}
                            tipPosition='bottom'
                            error={getLabel(388424,"主键未填写")}
                            style={{width: '100%'}}
                        >
                            <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@ir8mua`} className='portal-eoutdata-submit' value={primaryKey} viewAttr={3} onChange={value => this.setState({primaryKey: value})}/>
                        </WeaError>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@5bk5sc`} label={getLabel(16208,"链接地址")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@o8sl8t`} value={linkAddress} onChange={value => this.setState({linkAddress: value})}/>
                        <div style={{position: 'absolute', right: '-20px', top: '6px'}} >
                            <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@2aqaw9`}
                                title={getLabel(388008,"参数可设置如下内容：当前用户id，格式为{?userid}；当前用户登陆账号，格式为{?loginid}；当前用户姓名，格式为{?username}；当前用户编号，格式为{?workcode}；当前用户密码(MD5格式)，格式为{?password}；当前用户部门id，格式为{?departmentid}；当前用户部门编码，格式为{?departmentcode}；当前用户部门名称，格式为{?departmentname}；当前用户分部id，格式为{?subcompanyid}；当前用户分部编码，格式为{?subcompanycode}；当前用户分部名称，格式为{?subcompanyname}；并以'id='结束。")}
                            />
                        </div>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@uyq0j2`} label={getLabel(125405,"集成登录设置")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@13tacj`}
                            options={
                                tabNew.integrateLogin.options.map((item) => {
                                    return {key: item.key, selected: false, showname: item.value};
                                })
                            }
                            value={integrateLogin}
                            style={{width: '120px'}}
                            onChange={(value) => this.setState({integrateLogin: value})}
                        />
                    </WeaFormItem></div>);
        }else if(dataSourceType=='2'){
            dataSourceSetting = (
                <div>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@22sz63`} label={getLabel(110,"地址")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@5zrxkt`}
                            ref={el => {this.wsaddress = el}}
                            tipPosition='bottom'
                            error={getLabel(388427,"地址未填写")}
                            style={{width: '100%'}}
                        >
                            <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@uhchdf`} value={wsaddress} viewAttr={3} className='portal-eoutdata-submit' onChange={value => this.setState({wsaddress: value})}/>
                        </WeaError>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@fti2wp`} label={getLabel(604,"方法")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@m7v96m`}
                            ref={el => {this.method = el}}
                            tipPosition='bottom'
                            error={getLabel(388426,"方法未填写")}
                            style={{width: '100%'}}
                        >
                            <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@yi65d2`} value={method} viewAttr={3} className='portal-eoutdata-submit' onChange={value => this.setState({method: value})}/>
                        </WeaError>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@2j147f`} label={getLabel(561,"参数")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@osin4f`} value={parameters} onChange={value => this.setState({parameters: value})}/>
                        <div style={{position: 'absolute', right: '-20px', top: '6px'}} >
                            <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@ybuojd`}
                                title={getLabel(388009,"参数以xml格式输入,以root为根元素，并以属性名为子标签名（如：myName）")}
                            />
                        </div>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@6st587`} label={getLabel(21027,"主键")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@x5w12s`}
                            ref={el => {this.primaryKey = el}}
                            tipPosition='bottom'
                            error={getLabel(388424,"主键未填写")}
                            style={{width: '100%'}}
                        >
                            <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@mokfdq`} value={primaryKey} viewAttr={3} className='portal-eoutdata-submit' onChange={value => this.setState({primaryKey: value})}/>
                        </WeaError>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@d1069z`} label={getLabel(16208,"链接地址")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@ltzmob`} value={linkAddress} onChange={value => this.setState({linkAddress: value})}/>
                        <div style={{position: 'absolute', right: '-20px', top: '6px'}} >
                            <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@ljopxa`}
                                title={getLabel(388008,"参数可设置如下内容：当前用户id，格式为{?userid}；当前用户登陆账号，格式为{?loginid}；当前用户姓名，格式为{?username}；当前用户编号，格式为{?workcode}；当前用户密码(MD5格式)，格式为{?password}；当前用户部门id，格式为{?departmentid}；当前用户部门编码，格式为{?departmentcode}；当前用户部门名称，格式为{?departmentname}；当前用户分部id，格式为{?subcompanyid}；当前用户分部编码，格式为{?subcompanycode}；当前用户分部名称，格式为{?subcompanyname}；并以'id='结束。")}
                            />
                        </div>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@2am86s`} label={getLabel(125405,"集成登录设置")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@kgrgjy`}
                            options={
                                tabNew.integrateLogin.options.map((item) => {
                                    return {key: item.key, selected: false, showname: item.value};
                                })
                            }
                            value={integrateLogin}
                            style={{width: '120px'}}
                            onChange={(value) => this.setState({integrateLogin: value})}
                        />
                    </WeaFormItem></div>);
        }else if(dataSourceType=='3'){
            dataSourceSetting = (<div><WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@usra5m`} label={getLabel(33368,"内容")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                    <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@w4gd1o`}
                        ref={el => {this.content = el}}
                        tipPosition='bottom'
                        error={getLabel(388425,"内容未填写")}
                        style={{width: '100%'}}
                    >
                        <WeaTextarea ecId={`${this && this.props && this.props.ecId || ''}_WeaTextarea@kqtgcs`}
                            value={content}
                            viewAttr={3}
                            minRows={4}
                            onChange={value => {
                                this.setState({content: value})
                            }}
                            className='portal-eoutdata-submit'
                        />
                    </WeaError>
                        <div style={{position: 'absolute', right: '-24px', top: '40%'}} >
                            <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@5d0dik`}
                                title={getLabel(388010,"可设置http链接，比如http://ip:端口/.../*.jsp、*.php、*.asp，或者servlet等，输出格式必须为xml格式。参数可设置如下内容：当前用户id，格式为{?userid}；当前用户登陆账号，格式为{?loginid}；当前用户姓名，格式为{?username}；当前用户编号，格式为{?workcode}；当前用户密码(MD5格式)，格式为{?password}；当前用户部门id，格式为{?departmentid}；当前用户部门编码，格式为{?departmentcode}；当前用户部门名称，格式为{?departmentname}；当前用户分部id，格式为{?subcompanyid}；当前用户分部编码，格式为{?subcompanycode}；当前用户分部名称，格式为{?subcompanyname}；")}
                            />
                        </div>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@ynxo6q`} label={getLabel(21027,"主键")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@2oveuz`}
                            ref={el => {this.primaryKey = el}}
                            tipPosition='bottom'
                            error={getLabel(388424,"主键未填写")}
                            style={{width: '100%'}}
                        >

                            <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@u565il`} value={primaryKey} viewAttr={3} className='portal-eoutdata-submit' onChange={value => this.setState({primaryKey: value})}/>
                        </WeaError>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@baq3fh`} label={getLabel(16208,"链接地址")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@d5cr4w`} value={linkAddress} onChange={value => this.setState({linkAddress: value})}/>
                        <div style={{position: 'absolute', right: '-20px', top: '6px'}} >
                            <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@5aicnn`}
                                title={getLabel(388008,"参数可设置如下内容：当前用户id，格式为{?userid}；当前用户登陆账号，格式为{?loginid}；当前用户姓名，格式为{?username}；当前用户编号，格式为{?workcode}；当前用户密码(MD5格式)，格式为{?password}；当前用户部门id，格式为{?departmentid}；当前用户部门编码，格式为{?departmentcode}；当前用户部门名称，格式为{?departmentname}；当前用户分部id，格式为{?subcompanyid}；当前用户分部编码，格式为{?subcompanycode}；当前用户分部名称，格式为{?subcompanyname}；并以'id='结束。")
                                }
                            />
                        </div>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@wz0zj7`} label={getLabel(125405,"集成登录设置")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@gyw7mn`}
                            options={
                                tabNew.integrateLogin.options.map((item) => {
                                    return {key: item.key, selected: false, showname: item.value};
                                })
                            }
                            value={integrateLogin}
                            style={{width: '120px'}}
                            onChange={(value) => this.setState({integrateLogin: value})}
                        />
                    </WeaFormItem></div>);
        }
        if (sourceType == '1') {
            const columns = [{
                key: 'sourceName',
                title: getLabel(30231,"数据来源名称"),
                dataIndex: 'sourceName',
                width: '50%',
                render: (text, record) => (
                    <span>{record.sourceName}</span>
                )
            }, {
                key: 'integrateLogin',
                title: getLabel(125405,"集成登录设置"),
                width: '50%',
                render: (text, record) => (
                    <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@mjujbc@${record.sourceId}`}
                        options={
                            tabNew.integrateLogin.options.map((item) => {
                                return {key: item.key, selected: false, showname: item.value};
                            })
                        }
                        value={record.integrateLogin}
                        onChange={(value) => {
                            for (let i = 0, len = dataSourceList.length; i < len; i++) {
                                if (dataSourceList[i].sourceId == record.sourceId) {
                                    dataSourceList[i].integrateLogin = value;
                                    break;
                                }
                            }

                            this.setState({dataSourceList: dataSourceList});
                        }}
                    />
                )
            }];
                const { dataSourceList } = this.state;
                let sourceNamed;
                if(dataSourceList.length>0){
                    let sourceNames = dataSourceList[0].sourceName;
                    let sourceId = dataSourceList[0].sourceId;
                    sourceNamed = [{id : sourceId, name : sourceNames}];
                }
            existSetting = (
                <div>
                    <div style={{margin: '8px 0'}}>
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@qr33eo`}
                            ref={el => {this.exterbaldata = el}}
                            tipPosition='bottom'
                            error={getLabel(388428,"此项必写")}
                            style={{width: '100%'}}
                        >
                            <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@9kiikg`}
                                type="exterbaldata"
                                isSingle={true}
                                replaceDatas={sourceNamed||[]}
                                onChange={(id, name) => {
                                    this.setState({dataSourceList: [{key: id, sourceId: id, sourceName: name, integrateLogin: ''}]})
                                }}
                                viewAttr={3}
                            />
                        </WeaError>
                    </div>
                    <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@80jsg2`} columns={columns} dataSource={dataSourceList} pagination={false}/>
                </div>
            );
        } else if (this.state.sourceType == '2') {
            customSetting = (
                <div style={{marginLeft: '-30px'}}>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@jkgpjp`} label={getLabel(28006,"数据来源")} labelCol={{span: 8}} wrapperCol={{span: 15}}>
                        <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@jh9j83`}
                            options={
                                tabNew.dataSourceType.options.map((item) => {
                                    return {key: item.key, selected: false, showname: item.value};
                                })
                            }
                            value={dataSourceType}
                            style={{width: '120px'}}
                            onChange={(value) => this.setState({
                                dataSourceType: value,
                                content: '',
                                primaryKey: '',
                                linkAddress: '',
                                wsaddress: '',
                                method: '',
                                parameters: ''
                            })}
                        />
                    </WeaFormItem>
                    {dataSourceSetting}
                </div>
            );

            // 记录选中的行
            const _self = this;
            const rowSelection = {
                selectedRowKeys: _self.state.selectedRowKeys,
                onChange(selectedRowKeys) {
                    _self.setState({
                        selectedRowKeys
                    });
                }
            };

            const columns = [{
                key: 'showName',
                title:getLabel(15456, '字段显示名'),
                dataIndex: 'showName',
                width: '30%',
                render: (text, record,index) => (
                    <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@rna3vy@${record.key}`}
                        ref={el => {this[`showName${index}`] = el}}
                        tipPosition='bottom'
                        error={getLabel(388456,"字段显示名未填写")}
                        style={{width: '100%'}}
                    >
                        <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@0cggkb@${record.key}`} inputType='multilang' isBase64={true} value={record.showName} viewAttr={3} className='portal-eoutdata-submit' onChange={value => this.onShowFieldChange(record.key, 'showName', value)}/>
                </WeaError>)
            }, {
                key: 'showField',
                title:getLabel(32320,"显示字段/XML路径"),
                width: '30%',
                render: (text, record,index) => (
                    <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@vklo2t@${record.key}`}
                        ref={el => {this[`showField${index}`] = el}}
                        tipPosition='bottom'
                        error={getLabel(388457,"显示字段/XML路径未填写")}
                        style={{width: '100%'}}
                    >
                    <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@ytbo8v@${record.key}`} value={record.showField} viewAttr={3} className='portal-eoutdata-submit' onChange={value => this.onShowFieldChange(record.key, 'showField', value)}/>
                </WeaError>)
            }, {
                key: 'isTitle',
                title: getLabel(22965, '标题栏'),
                width: '10%',
                render: (text, record) => (
                    <Checkbox ecId={`${this && this.props && this.props.ecId || ''}_Checkbox@f38gek@${record.key}`} checked={record.isTitle} onChange={e => this.onShowFieldChange(record.key, 'isTitle', e.target.checked)}/>
                )
            }, {
                key: 'transformMethod',

                title: <div><span>{getLabel(32321,"转换方法")}</span>
                    <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@mg9w82@${record.key}`}
                        title={getLabel(131015,"参数可设置如下内容，格式为：select 最终字段 from tablename where 条件字段={?currentvalue}，{?currentvalue}表示当前值")}
                    /></div>,
                width: '30%',
                render: (text, record) => (
                    <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@qfmgb9@${record.key}`} value={record.transformMethod} onChange={value => this.onShowFieldChange(record.key, 'transformMethod', value)}/>
                )
            }];
            const { selectedRowKeys } = this.state;
            fieldSetting = (
                <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@qpdb8n`} title={getLabel(21903,"字段设置")} needTigger={true} showGroup={true} customComponent={
                    <div>
                        <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@uzckk8`} type="primary" className="portal-esetting-wsg-btn" onClick={this.onAdd}>
                            <Icon ecId={`${this && this.props && this.props.ecId || ''}_Icon@6zwztp`} type="plus" style={{color: '#fff'}}/>
                        </Button>
                        <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@ckcg08`} type="primary" className="portal-esetting-wsg-btn" disabled={!(selectedRowKeys && selectedRowKeys.length)} onClick={this.onDelete}>
                            <Icon ecId={`${this && this.props && this.props.ecId || ''}_Icon@hxx8vv`} type="minus" style={{color: '#fff'}}/>
                        </Button>
                    </div>
                }>
                    <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@zbykp0`} rowSelection={rowSelection} columns={columns} dataSource={showFieldSetting} pagination={false}/>
                </WeaSearchGroup>
            );
        }

        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@nlwaot`}
                className="portal-esetting-dialog"
                visible={true}
                title={getLabel(19480, '内容设置')}
                icon="icon-coms-portal"
                iconBgcolor='#1a57a0'
                style={{width: 660, height: 500}}
                hasScroll={true}
                buttons={this.getButtons()}
                onCancel={this.onCancel}
            >
                <WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@h7h8ao`} title={getLabel(24128, '基本设置')} needTigger={true} showGroup={true}>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@bza2pv`} label={getLabel(24986, '标题')} labelCol={{span: 4}} wrapperCol={{span: 18}}>
                        <WeaError ecId={`${this && this.props && this.props.ecId || ''}_WeaError@jy4vjx`}
                            ref={el => {this.title = el}}
                            tipPosition='bottom'
                            error={getLabel(388176,"标题未填写")}
                            style={{width: '100%'}}
                        >
                            <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@vbpmxb`} inputType="multilang" isBase64={true} className='portal-eoutdata-submit' value={title} viewAttr={3} onChange={value => this.setState({title: value,oldtitle: title})}/>
                        </WeaError>
                    </WeaFormItem>
                    <WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@fj5v9n`} label={getLabel(125929,"数据类型")} labelCol={{span: 4}} wrapperCol={{span: 18}}>
                    <div style={{paddingTop:'5px'}}>
                        <RadioGroup ecId={`${this && this.props && this.props.ecId || ''}_RadioGroup@x7pa2e`} value={sourceType} onChange={e => this.setState({sourceType: e.target.value})}>
                            <Radio ecId={`${this && this.props && this.props.ecId || ''}_Radio@3n8to6`} value="1">{getLabel(81511,"已有数据集成")}</Radio>
                            <Radio ecId={`${this && this.props && this.props.ecId || ''}_Radio@nsafd1`} value="2">{getLabel(32219,"自定义方式")}</Radio>
                        </RadioGroup>
                        {existSetting}
                        {customSetting}
                    </div> 
                    </WeaFormItem>
                </WeaSearchGroup>
                {fieldSetting}
            </WeaDialog>
        );
    }

    getButtons() {
        let buttons = [];
        buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@47lril`} type="primary" onClick={this.onOk}>{getLabel(826, '确定')}</Button>);
        buttons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@5rqnbh`} type="primary" onClick={this.onCancel}>{getLabel(31129, '取消')}</Button>);
        return buttons;
    }

    onOk() {
        const{ title, content = '',dataSourceType, sourceType,dataSourceList,showFieldSetting, primaryKey = '', wsaddress, method } = this.state;
        let isPass = true;
        if(title == ''){
            this.title.showError();
            isPass = false;
        }

        if(sourceType == '1' && dataSourceList.length == 0 || dataSourceList[0] && !dataSourceList[0].sourceName){
            this.exterbaldata.showError();
            isPass = false;
        }else if(sourceType == '2'){
            if(showFieldSetting.length=='0'){
                Modal.warning({
                    title: getLabel(15172, '系统提示'),
                    content:getLabel(388012,'必须设置显示字段！')
                });
                return;
            }else{
                let length = 0;
                if(dataSourceType == '1' || dataSourceType == '3'){
                    if(content == ''){
                        this.content.showError();
                        isPass = false;
                    }else if(primaryKey == ''){
                        this.primaryKey.showError();
                        isPass = false;
                    }
                }else if(dataSourceType == '2'){
                    if(wsaddress == ''){
                        this.wsaddress.showError();
                        isPass = false;
                    }else if(method == ''){
                        this.method.showError();
                        isPass = false;
                    }else if(primaryKey == ''){
                        this.primaryKey.showError();
                        isPass = false;
                    }
                }
                if(isPass)this.props.onOk(this.state);
                showFieldSetting.map((item,index) => {
                    this[`tableEdit${index}`] && this[`tableEdit${index}`].refs.edit.doRequiredCheck();
                    if(item.showName == ''){
                        this[`showName${index}`].showError();
                        isPass = false;
                        return;
                    }else if(item.showField == ''){
                        this[`showField${index}`].showError();
                        isPass = false;
                        return;
                    }
                    if(!item.isTitle){
                        length= length + 1;
                    }

                })
                if(length == showFieldSetting.length){
                    Modal.warning({
                        title: getLabel(15172, '系统提示'),
                        content:getLabel(388013,'请设置标题栏字段！')
                    });
                    return;
                }
            }

        }
        if(isPass) this.props.onOk(this.state)
    }
    onCancel() {
        this.props.onCancel();
    }

    onAdd() {
        let showFieldSetting = this.state.showFieldSetting;
        let key = showFieldSetting.length;

        showFieldSetting.push({
            key: key,
            showName: '',
            showField: '',
            isTitle: false,
            transformMethod: ''
        });

        this.setState({showFieldSetting: showFieldSetting});
    }

    onDelete() {
        let showFieldSetting = this.state.showFieldSetting;
        const { selectedRowKeys } = this.state;
        Modal.confirm({
            title: getLabel(386786,'信息确认'),
            content: getLabel(385625,'确定要删除选择的记录吗？'),
            onOk: () => {
                if (selectedRowKeys && selectedRowKeys.length) {
                    const __selectedRowKeys = selectedRowKeys.slice();
                    for (let i = 0, len = __selectedRowKeys.length; i < len; i++) {
                        selectedRowKeys.splice(i, 1);

                        for (let j = 0, len2 = showFieldSetting.length; j < len2; j++) {
                            if (showFieldSetting[j].key == __selectedRowKeys[i]) {
                                showFieldSetting.splice(j, 1);
                                break;
                            }
                        }
                    }

                    this.setState({showFieldSetting: showFieldSetting});
                    this.setState({selectedRowKeys: []});
                }
            },
        });

    }

    onShowFieldChange(key, type, value) {
        let showFieldSetting = this.state.showFieldSetting;
        if (type == 'isTitle') {
            for (let i = 0, len = showFieldSetting.length; i < len; i++) {
                showFieldSetting[i]['isTitle'] = false;
            }
            showFieldSetting[key]['isTitle'] = value;
        } else {
            showFieldSetting[key][type] = value;
        }

        this.setState({showFieldSetting: showFieldSetting});
    }
}

export default Content_OutData_DataSource;